<?php
/* 
 * class.collect.php
 * 我的城市首页-商家收藏
 * @author samuel
 * @date 2009-05-23
 */
include_once 'class.mycityBase.php';
class mycity_collect extends mycityBase {
    private $seller_id;


    function  __construct($core) {
        parent::__construct();
        //参数处理
	    $this->step = $this->params['step'] ? strtolower(trim($core->params['step'])) : 'index';
	    $this->seller_id = $this->params['sid'] ? (int)$this->params['sid'] : 0;
	    $this->user_id = $this->params['uid'] ? (int)$this->params['uid'] : 1;
	    if(!$this->user_id){
		    $this->error = "用户ID不合法！";
		    $this->jumpError();
		    exit;
	    }
	    if(!$this->seller_id){
		    $this->error = "商家ID不合法！";
		    $this->jumpError();
		    exit;
	    }

        $run = "run_" . $this->step;
        
        //header("Content-type: text/vnd.wap.wml");
        $this->$run();
    }
    
    
    
    function run_index(){
        $page_title = "我的城市-收藏商家";
    	$backurl = $_SERVER['PHP_SELF'] . '?act=sellerinfo&sid=' . $this->seller_id . '&uid=' . $this->user_id;
    	
        //判断是否已经收藏过
        $tag = $this->core->load('myhome::myhomeBase')->getUserFavorites($this->user_id, $this->seller_id, true);
        if($tag){
            $this->error = "对不起，您已经对收藏过商家了！";
            $this->jumpError("", $page_title, $backurl);
            exit;
        }
        
        $sql = "INSERT INTO `fun_user_favorites` SET `UserID`='".$this->user_id."', `SellerID`='".$this->seller_id."', `collectTime`=now()";
        $res = $this->core->db->query($sql);
        if($res){
            $content = "收藏成功！";
        }else{
            $content = "收藏失败！";
        }

    	$this->jumpPrompt($content, $page_title, $backurl);
    }
}


?>
